#!/user/bin/env node

const db = require('./database.js');

TodoList = function(){
}

TodoList.prototype.getAll = function(callback){
  const sql = 'SELECT * FROM todo';
  let items = [];

  db.query(sql,function(err,results){
    if(err){
      callback(true);
      return;
    }

    results.forEach((e)=>{item.push(e.item);})
    callback(false,items);
  });
};

TodoList.prototype.addItem = function(item,callback){
  const sql = 'SELECT * FROM todo(item) VALUES(?)';

  db.query(sql,[item],function(err,results){
    if(err){
      callback(true);
      return;
    }
    callback(false,results);
  });
};

module.exports = TodoList;
